﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.Domain.MonitorDomain
{
   

    public class MonitorConfigInfoService : IMonitorConfigInfoService
    {
        private IMonitorConfigInfoRepository _IMonitorConfigInfoRepository;
    
        public MonitorConfigInfoService(IMonitorConfigInfoRepository monitorConfigInfoRepository)
        {
            _IMonitorConfigInfoRepository = monitorConfigInfoRepository;
        }

        public async Task<List<MonitorConfigInfo>> GetMonitorConfigInfoByFloorAsync(string floor)
        {

            var exp = Expressionable.Create<MonitorConfigInfo>();
            exp.AndIF(!string.IsNullOrEmpty(floor), l => l.Name.Contains(floor));
          
            var result = await _IMonitorConfigInfoRepository.AsSugarClient().Queryable<MonitorConfigInfo>().Where(exp.ToExpression()).ToListAsync();

            return result;
        }

        public async Task<bool> UpdateMonitorConfigInfoByLayerAsync(string layer,string json)
        {

            return await _IMonitorConfigInfoRepository.UpdateAsync(it => new MonitorConfigInfo()
            {
               Json = json,
            },
          it => it.Name == layer);

            
        }
    }
}
